﻿package mortal.game.view.pack.social
{
    import com.gengine.global.*;
    import com.mui.controls.*;
    import com.mui.utils.*;
    import extend.language.*;
    import flash.events.*;
    import mortal.component.window.*;
    import mortal.game.events.*;
    import mortal.game.mvc.*;
    import mortal.game.resource.info.item.*;
    import mortal.game.scene3D.map3D.*;
    import mortal.game.view.common.*;
    import mortal.game.view.common.item.*;
    import mortal.mvc.core.*;

    public class BulkUseWin extends SmallWindow
    {
        private var _propItem:BaseItem;
        private var _textField:GTextFiled;
        private var _numInput:NumInput;
        private var _btnOK:GButton;
        private var _btnCancel:GButton;
        private static var _itemData:ItemData;
        private static var _instance:BulkUseWin;

        public function BulkUseWin()
        {
            this.setSize(240, 145);
            title = Language.getString(35479);
            if (_instance != null)
            {
                throw new Error(" BulkUseWin 单例 ");
            }
            return;
        }// end function

        override public function show(param1:int = 0, param2:int = 0) : void
        {
            var _loc_3:int = 0;
            var _loc_4:int = 0;
            if (this.isHide)
            {
                _loc_3 = Global.stage.mouseX - 80;
                _loc_4 = Global.stage.mouseY - 112;
                if (_loc_3 < 0)
                {
                    _loc_3 = 0;
                }
                else if (_loc_3 + this.width > SceneRange.display.width)
                {
                    _loc_3 = SceneRange.display.width - this.width;
                }
                if (_loc_4 < 0)
                {
                    _loc_4 = 0;
                }
                else if (_loc_4 + this.height > SceneRange.display.height)
                {
                    _loc_4 = SceneRange.display.height - this.height;
                }
                super.show(_loc_3, _loc_4);
            }
            return;
        }// end function

        public function set itemData(param1:ItemData) : void
        {
            _itemData = param1;
            this._numInput.maxNum = _itemData.serverData.itemAmount;
            return;
        }// end function

        override protected function createDisposedChildrenImpl() : void
        {
            super.createDisposedChildrenImpl();
            this._propItem = UICompomentPool.getUICompoment(BaseItem);
            this._propItem.createDisposedChildren();
            this._propItem.setSize(36, 36);
            this._propItem.move(25, 46);
            this._propItem.amount = 1;
            this.addChild(this._propItem);
            this._textField = UIFactory.gTextField("", 73, 42, 150, 20, this, null, true);
            this._textField.htmlText = "<font color=\'#ffffff\' size=\'13\'>" + Language.getString(30031) + "</font>";
            this._numInput = UIFactory.numInput(66, 68, this, 1);
            this._numInput.width = 105;
            this._numInput.height = 22;
            this._btnOK = UIFactory.gButton(Language.getString(30026), 45, 95, 49, 28, this);
            this._btnOK.configEventListener(MouseEvent.CLICK, this.bulkHandler);
            this._btnCancel = UIFactory.gButton(Language.getString(30027), 145, 95, 49, 28, this);
            this._btnCancel.configEventListener(MouseEvent.CLICK, this.CloseHandler);
            return;
        }// end function

        override protected function disposeImpl(param1:Boolean = true) : void
        {
            this._propItem.dispose(param1);
            this._textField.dispose(param1);
            this._btnOK.dispose(param1);
            this._btnCancel.dispose(param1);
            this._numInput.dispose(param1);
            this._propItem = null;
            this._textField = null;
            this._btnOK = null;
            this._btnCancel = null;
            this._numInput = null;
            super.disposeImpl(param1);
            return;
        }// end function

        private function bulkHandler(event:MouseEvent) : void
        {
            var _loc_2:* = this._numInput.currentNum;
            if (_loc_2 > 0 && _loc_2 <= _itemData.serverData.itemAmount)
            {
                Dispatcher.dispatchEvent(new DataEvent(EventName.BackPack_BulkUse, {itemData:_itemData, amount:_loc_2}));
                this.hide();
            }
            return;
        }// end function

        private function CloseHandler(event:MouseEvent) : void
        {
            this.hide();
            return;
        }// end function

        public static function get instance() : BulkUseWin
        {
            if (_instance == null)
            {
                _instance = new BulkUseWin;
            }
            return _instance;
        }// end function

    }
}
